#include <iostream>
#include <vector>
#include <climits>
#include <queue>
#define int long long
using namespace std;

struct node
{
    int v, w;
};
// 已知
int m, n; // m行n列
vector<node> g[100];
int u, v, w;
// 未知
int min_dist = LONG_LONG_MAX;
int vis[100] = {0};

void input()
{
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        cin >> u >> v >> w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
}
void dfs(int u, int lim)
{
    if (u == n)
    {
        min_dist = min(min_dist, lim);
    }
    vis[u] = 1;
    for (auto &e : g[u])
    {
        if (!vis[e.v])
            dfs(e.v, lim ^ e.w);
    }
    vis[u] = 0;
}

signed main()
{
    input();
    dfs(1, 0);
    cout << min_dist << endl;
    return 0;
}